package cn.qrx.gateway.authorization.auth;


import cn.qrx.gateway.authorization.GatewayAuthorizingToken;
import cn.qrx.gateway.authorization.IAuth;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * @Author: 屈燃希
 * @Date: 2025/10/27
 * @Version: V1.0
 * @Description:
 */
public class AuthService implements IAuth {


    private Subject subject;

    public AuthService() {

        IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:shiro.ini");
        SecurityManager instance = factory.getInstance();
        SecurityUtils.setSecurityManager(instance);
        this.subject= SecurityUtils.getSubject();
    }

    public boolean validate(String id, String token)
    {
        try {
            subject.login(new GatewayAuthorizingToken(id,token));
            return subject.isAuthenticated();
        } finally {
            subject.logout();
        }
    }
}
